package com.xyzwps.example.stream;

import java.util.Objects;

public class ArrayStream<T> extends Stream<T> {
    private final T[] array;

    private int cursor;

    public ArrayStream(T[] array) {
        this.array = Objects.requireNonNull(array);
        this.cursor = 0;
    }

    @Override
    public Parcel<T> next() {
        if (cursor < array.length) {
            return Parcel.deliver(array[cursor++]);
        }
        return Parcel.done();
    }
}
